<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>接口监控</title>
    <link rel="stylesheet" th:href="@{/component/pear/css/pear.css}"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">接口URI</label>
                    <div class="layui-input-inline">
                        <input type="text" name="uri" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="user-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <!--		表格-->
        <table id="user-table" lay-filter="user-table"></table>
    </div>
</div>

<script type="text/html" id="user-Time">
    {{#  if(d.time !=null){ }}
    <div>{{layui.util.toDateString(d.time, 'yyyy-MM-dd HH:mm:ss')}}</div>
    {{#  } else {}}
    <div>{{}}</div>
    {{#  } }}
</script>


<script th:src="@{/component/layui/layui.js}"></script>
<script th:src="@{/component/pear/pear.js}"></script>
<script>
    layui.use(['table', 'form', 'jquery', 'common'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;


        let cols = [
            [{
                type: 'checkbox'
            },
                {
                    title: 'id',
                    field: 'id',
                    align: 'center',
                    width: 100
                },
                {
                    title: '接口URI',
                    field: 'uri',
                    align: 'center'
                },
                {
                    title: '接口耗时',
                    field: 'calc',
                    align: 'center'
                },
                {
                    title: '访问接口时间',
                    field: 'time',
                    align: 'center',
                    templet: '#user-Time'
                }
            ]
        ]

        table.render({
            elem: '#user-table',
            url: '/pear/data/monitorInterface',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: false,
            text: {none: '暂无信息'},
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });


        form.on('submit(user-query)', function (data) {
            table.reload('user-table', {
                where: data.field
            })
            return false;
        });


        window.refresh = function (param) {
            table.reload('user-table');
        }
    })
</script>
</body>
</html>
